package com.edu.framework.websocket.handler;

import cn.hutool.core.bean.BeanUtil;
import com.edu.framework.websocket.WebSocketHolder;
import com.edu.framework.websocket.message.base.Response;
import com.edu.framework.websocket.message.examseat.ExamSeatRequest;
import com.edu.framework.websocket.message.examseat.ExamSeatVO;
import com.edu.framework.websocket.message.highlights.HighlightsRequest;
import com.edu.framework.websocket.message.tclass.ClassRequest;
import com.edu.framework.websocket.message.tclass.ClassVO;
import com.edu.framework.websocket.service.ExamSeatService;
import com.edu.system.domain.TClass;
import com.edu.system.service.ITClassService;
import com.edu.system.service.ITExamSeatService;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

@Component
public class ExamSeatRequestHandler implements IHandler<ExamSeatRequest> {

    @Resource
    private ExamSeatService wsExamSeatService;

    @Override
    public void execute(WebSocketSession session, ExamSeatRequest message) {
        if (message == null) {
            return;
        }
        Map<String, String> data = message.getData();
        String id = data.get(ExamSeatRequest.CLASS_ID_KEY);
        Response<ExamSeatVO> response = null;

        if (id == null){
            response = Response.fail(ExamSeatRequest.TYPE, "班级id不能为空");
        } else {
            response = wsExamSeatService.getSeat(Long.parseLong(id));
        }

        try {
            WebSocketHolder.send(session,response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    public String getType() {
        return ExamSeatRequest.TYPE;
    }
}
